package com.quick.springbootquicky.mapper;

import com.quick.springbootquicky.pojo.Article;
import org.apache.ibatis.annotations.*;
import org.springframework.data.repository.query.Param;

import java.util.List;

@Mapper
public interface ArticleMapper {

    /**
     * 添加新的文章
     * @param article
     */
    @Insert("insert into article (title,content,create_user,cover_img,state,category_id,create_time,update_time)" +
            " values(#{title},#{content},#{createUser},#{coverImg},#{state},#{categoryId},#{createTime},#{updateTime})")
    void add(Article article);

    /**
     * 查询列表数据
     * @param article
     * @return
     */
    List<Article> list(Article article);

    /**
     * 更新文章
     * @param article
     */
    @Update("update article set title =#{title},content=#{content},state=#{state},create_user=#{createUser},cover_img=#{coverImg}" +
            ",category_id=#{categoryId},update_time=#{updateTime} where id=#{id}")
    void update(Article article);

    /**
     * 更新状态
     * @param id
     * @param state
     */
    @Update("update article set state=#{state} where id=#{id}")
    void updateState(Integer id, String state);

    @Delete("delete from article where id=#{id}")
    void delete(Integer id);
}
